package net.hancl.modules.sys.controller;

import net.hancl.common.bean.ResultBean;
import net.hancl.common.exception.MessageCode;
import net.hancl.modules.sys.bean.UserBean;
import net.hancl.modules.sys.service.IUserService;
import net.hancl.modules.sys.utils.UserUtils;
import net.hancl.modules.sys.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "sys/user")
public class UserController {

    @Autowired
    private IUserService userService;
    @Autowired
    private UserUtils userUtils;

    @RequestMapping(value = "getUser", method = RequestMethod.GET)
    @ResponseBody
    public ResultBean getCommentUser(HttpServletRequest request,
                                     HttpServletResponse response, UserVo userVo) {
        ResultBean rb = new ResultBean();

        UserBean user = userUtils.getUserBean();
        if (user == null || user.getId() == null) {
            return new ResultBean(false, MessageCode.PLASS_LOGIN, "请登陆系统");
        }

        // 获取当前用户 信息
        if (userVo == null) {

            rb.setData(user);
            return rb;
            // return new ResultBean(false, MessageCode.ARGUMENT_ILLEGAL,
            // "系统参数不合法");
        }

        try {
            UserBean userBean = userService.get(userVo.getId());
            rb.setData(userBean);
        } catch (Exception e) {
            e.printStackTrace();
            rb = new ResultBean(false, MessageCode.SYS_ERROR, "异统异常");
        }
        return rb;
    }

}
